import random
import hashlib


# 验证码
def creat_code(num, mode='code'):
    code = ''
    for i in range(num):
        code_list = [str(random.randint(0, 9)), chr(random.randint(65, 90)), chr(random.randint(97, 122))]
        if mode == 'bank_id':
            # 银行卡号随机生成纯数字
            code_member = random.choice(code_list[0])
            code += code_member
        elif mode == 'code':
            code_member = random.choice(code_list)
            code += code_member
    return code


# 加密数据
def encrypt(data, salt=''):
    md5 = hashlib.md5()
    encrypt_data = data.encode('utf8')
    md5.update(encrypt_data)
    data = md5.hexdigest()
    data += salt
    return data
